﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Data;

namespace FireZone.Converters
{
    internal class StorageSizeConverter : IValueConverter
    {
        [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
        public extern static StringBuilder StrFormatByteSizeW(ulong qdw, StringBuilder pszBuf, uint cchBuf);

        #region IValueConverter Members

        object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return Binding.DoNothing;
            StringBuilder strValue = new StringBuilder(1024);
            return StrFormatByteSizeW((ulong)value, strValue, (uint)strValue.Capacity).ToString();
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
